#ifndef __CSERVER_H__
#define __CSERVER_H__
#include <set>
#include <sys/select.h>

class CClient;

class CServer{
public:
    CServer(const char * ip, int port, int backlog, int client_send_buffer_size, int client_recv_buffer_size);

    virtual ~CServer();

    virtual void onClientJoin(CClient * client);

    virtual void onClientLeave(CClient * client);

    CClient * accept();

    void remove_client(CClient * client);

    void main();

    int socket(){
        return m_sockfd;
    }
private:
    //所有的客户端
    std::set<CClient*> m_clients;
    //持有的socket
    int m_sockfd = -1;
    int m_client_send_buffer_size = 0;
    int m_client_recv_buffer_size = 0;
    fd_set m_read_set;
    fd_set m_read_set_bek;
    fd_set m_write_set;
    int m_max_fd = -1;
    bool m_clients_has_change = true;
};

#endif
